<?php

namespace App\Controller\InsideService;

use App\Model\QmGameVersion;

class GameUserInside extends BaseInside {

    /**
     * 获取用户列表
     * @param array $data
     * @return array
     */
    public function index(array $data): array {
        return $this->getInfo('GameUser/index', $data);
    }

    /**
     * 获取单个用户数据
     * @param $game_hash
     * @param $openid
     * @return mixed
     */
    public function getUserInfoByOpenid($game_hash, $openid): mixed {
        return $this->getInfo('GameUser/getUserInfoByOpenid', [
            'game_hash' => $game_hash,
            'openid'    => $openid
        ]);
    }

    /**
     * 封禁用户
     * @param int $id
     * @param string $game_hash
     * @param string $isDelItem
     * @param string $isDelEquipment
     * @return array
     */
    public function blackUser(int $id, string $game_hash, string $isDelItem = 'no', string $isDelEquipment = 'no'): array {
        return $this->getInfo('GameUser/blackUser', [
            'id'             => $id,
            'game_hash'      => $game_hash,
            'isDelItem'      => $isDelItem,
            'isDelEquipment' => $isDelEquipment
        ]);
    }

    /**
     * 封榜用户
     * @param int $id
     * @param string $game_hash
     * @return array
     */
    public function rankBlackUser(int $id, string $game_hash): array {
        return $this->getInfo('GameUser/rankBlackUser', [
            'id'        => $id,
            'game_hash' => $game_hash,
        ]);
    }

    /**
     * 禁言用户
     * @param array $data
     * @return array
     */
    public function mute(array $data): array {
        return $this->getInfo('GameUser/mute', $data);
    }

    /**
     * 实时人数
     * @param string $game_hash
     * @return array
     */
    public function onlineCount(string $game_hash = ''): array {
        return $this->getInfo('GameUser/onlineCount', [
            'game_hash' => $game_hash,
        ]);
    }

    /**
     * 获取用户信息
     * @param $token
     * @param $code
     * @return mixed
     */
    public function getUserInfoByToken($token, $code): mixed {
        $res = $this->setCode($code)->getInfo('GameUser/getUserInfoByToken', ['user_token' => $token]);

        return $res['data'];
    }

    /**
     * 描述: 判断是否存在角色
     * 日期: 2023/3/15 16:38
     * @param $data
     * @return mixed
     * @author: cinder
     */
    public function getExistRole($data): mixed {
        $res = $this->postInfo('GameUser/existRole', [
            'game_hash' => $data['game_hash'],
            'openid'    => $data['openid'],
            'hero_id'   => $data['hero_id'],
        ]);
        return $res['data'];
    }


    /**
     * 描述:获取组队服务器配置
     * 日期: 2023/3/15 16:38
     * @param $game_hash
     * @param string $conf_key
     * @return mixed
     * @author: cinder
     */
    public function getGameVersion($game_hash, string $conf_key = ''): mixed {
        $res = $this->postInfo('GameConfig/gameVersion', ['game_hash' => $game_hash, 'conf_key' => $conf_key]);
        return $res['data'];
    }

    /**
     * 保存用户unionid
     * @param array $data
     * @return array
     */
    public function saveUnionid(array $data): array {
        return $this->getInfo('GameUser/saveUnionid', $data);
    }

    /**
     * 角色列表
     * @param string $size
     * @param string $uid
     * @param int $page
     * @param string $game_hash
     * @return array
     */
    public function roleList(string $size = '', string $uid = '', int $page = 1, string $game_hash = ''): array {
        return $this->getInfo('GameUser/roleList', [
            'page'      => $page,
            'size'      => $size,
            'uid'       => $uid,
            'game_hash' => $game_hash,
        ]);
    }
}